package com.seeyon.apps.kkARPEvent.util;

import java.util.Map;
import java.util.TreeMap;

/**
 * @author: wd
 * Date: 2020/12/7 10:26
 * Description : API标准化生成sign的类
 */
public class SignUtil {

    /**
     * 生成当前时间戳
     * @return
     */
    public static Long getCurrentTimeStamp(){
        return System.currentTimeMillis();
    }

    /**
     * 生成接口签名
     */
    public static String getSign(String appId, String timeStamp, String key, String url, String method, Map<String, String> params){
        StringBuilder sb = new StringBuilder();
        Map<String, String> sortParams = new TreeMap<>(params);
        sb.append(appId).append(timeStamp);
        for (Map.Entry<String, String> entry : sortParams.entrySet()) {
            String value = entry.getValue() == null ? "" : entry.getValue().trim();
            sb.append(value);
        }
        sb.append(key).append(url).append(method);
        return MD5Util.getMD5String(sb.toString()).toUpperCase();
    }


}
